package com.code.chatroom.server

import io.netty.channel.ChannelInitializer
import io.netty.channel.socket.SocketChannel
import io.netty.handler.codec.string.StringDecoder
import io.netty.handler.codec.string.StringEncoder
import io.netty.util.CharsetUtil

/**
 * 初始化通道Handler
 */
class InitChannelHandler : ChannelInitializer<SocketChannel>() {
    override fun initChannel(ch: SocketChannel) {
        // 向pipeline加入解码器
        ch.pipeline().addLast("decoder", StringDecoder(CharsetUtil.UTF_8))
        // 向pipeline加入编码器
        ch.pipeline().addLast("encoder", StringEncoder(CharsetUtil.UTF_8))
        // 向pipeline加入自己的业务处理Handler
        ch.pipeline().addLast("serverHandler", ServerHandler())
    }
}